﻿using System.Threading;
using App.Business.Party;
using RrslLite;
using RrslLite.Dsl;
using RrslLite.Net;
using RrslLite.Net.Attributes;
using RrslLite.Net.BatchImpl;
using RrslLite.Net.Proxies;

namespace App.Test.AopWcf
{
	/// <summary>
	/// Summary description for BatchFactoryTEST
	/// </summary>
	public class BatchFactoryTest
	{

		public void Run1()
		{
			KnownTypeProvider.RegisterModelDomainNamespace("App.Business.Entities");
			
			var @eventCall1 = new ManualResetEvent(false);
			var @eventCall2 = new ManualResetEvent(false);
			var @eventCall3 = new ManualResetEvent(false);

			IBatchBuilder factory = new AsyncBatchBuilder();

			factory
				.Call<IPersonFacade>()
					.WithQuery(f => f.GetActivePersonsFor("CZ"), list =>
					{
						@eventCall1.Set();
					})
					.WithQuery(f => f.GetMostImportantPersonFor("DE"), person =>
					{
						@eventCall2.Set();

                    })
				.Call<ICountryFacade>()
					.WithQuery(f => f.GetByCode("CZ"), country =>
					{
						@eventCall3.Set();
                    })
			.Execute();

			@eventCall1.WaitOne();
			@eventCall2.WaitOne();
			@eventCall3.WaitOne();
			//WaitHandle.WaitAll(new[] {@eventCall1, @eventCall2} );
		}
	}
}
